package com.example.demo.service.Impl;

import com.example.demo.entity.AdminAccount;
import com.example.demo.entity.CoachAccount;
import com.example.demo.entity.LoginForm;
import com.example.demo.entity.StudentAccount;
import com.example.demo.mapper.*;
import com.example.demo.service.LoginService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Slf4j
@Service
@RequiredArgsConstructor
public class LoginImpl implements LoginService {
    private final StudentMapper studentMapper;
    private final CoachMapper coachMapper;
    private final AdminMapper adminMapper;
    private final StudentAccountMapper studentAccountMapper;
    private final CoachAccountMapper coachAccountMapper;
    private final AdminAccountMapper adminAccountMapper;
    @Override
    public Object login(LoginForm loginForm) {
        if(loginForm.getRole().equals("学员")){
            StudentAccount studentAccount = studentAccountMapper.findByUsernameAndPassword(loginForm.getUsername(),loginForm.getPassword());
        if(studentAccount!=null){
            return studentAccount;
        }
        }
        else if(loginForm.getRole().equals("管理员")){
            AdminAccount adminAccount = adminAccountMapper.findByUsernameAndPassword(loginForm.getUsername(),loginForm.getPassword());
            if(adminAccount!=null){
                return adminAccount;
            }
        }
        else{
            CoachAccount coachAccount = coachAccountMapper.findByUsernameAndPassword(loginForm.getUsername(),loginForm.getPassword());
            if(coachAccount!=null){
                return coachAccount;
            }
        }
        return false;
    }
}
